//
//  HeaderCollectionReusableView.m
//  礼物说分类
//
//  Created by mafeng on 16/8/2.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "HeaderCollectionReusableView.h"
#import "TopCollectionViewCell.h"
#define kTopLableAndImageCollectionViewReuse @"topLabelAndImage"

@interface HeaderCollectionReusableView ()<UICollectionViewDelegate, UICollectionViewDataSource>

@end
@implementation HeaderCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _lanmuLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 20)];
        //_lanmuLabel.backgroundColor = [UIColor cyanColor];
        _lanmuLabel.text = @"栏目";
        [self addSubview:_lanmuLabel];
        
        _allButton = [[UIButton alloc] initWithFrame:CGRectMake(200, 0, 100, 20)];
        _allButton.backgroundColor = [UIColor cyanColor];
        [_allButton setTitle:@"查看全部" forState:UIControlStateNormal];
        [self addSubview:_allButton];
        
        // 创建layout及设置他的一些属性
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(200, 90);
        layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        layout.minimumLineSpacing = 5;
        layout.minimumInteritemSpacing = 5;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        // 创建collectionview及一些属性
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 30, self.bounds.size.width, self.bounds.size.width - 30)collectionViewLayout:layout];
        [_collectionView registerClass:[TopCollectionViewCell class] forCellWithReuseIdentifier:kTopLableAndImageCollectionViewReuse];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [self addSubview:_collectionView];
        _collectionView.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
// collection 的协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 18;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kTopLableAndImageCollectionViewReuse forIndexPath:indexPath];
    //cell.backgroundColor = [UIColor greenColor];
    return cell;
}
@end
